﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data.OleDb;
using System.Data;
using Common.Logging;
using Utility;
using AppToolKit.Data;
using AppToolKit.Core.Context.Spring;

namespace DALFactory.DataBase
{
    public class AccessHelper : IAutoWiring
    {
        ILog log = LogManager.GetLogger(LogDefault.AppInfo);
       

        public string ConnectionStr
        {
            get;
            set;
        }
       [AutoWiring]
        public IDbProcessor DbProcessor { get; set; }
       

        public OleDbConnection GetConnection()
        {
            OleDbConnection con = DbProcessor.CreateConnection()  as OleDbConnection;
            return con;
        }
        // public OleDbDataAdapter GetDataAdapter(string text, OleDbConnection con)
        //{
        //    OleDbDataAdapter da= DbProcessor.GetDataAdapter();
        //     da.sele
        //    OleDbDataAdapter da = new OleDbDataAdapter(text, con) ;
        //     return da;
        //}
        public DataSet GetDataSet(CommandType commandType, string commandText)
        {
          return   DbProcessor.ExecuteDataSet(commandType, commandText);
            //DataSet ds=new DataSet();
            //da.Fill(ds);
            //return ds;

        }
        public void ExecuteNonQuery(CommandType commandType, string commandText)
        {
            // OleDbConnection con=GetConnection();
            ////try
            ////{
             
            //OleDbCommand cmd=new OleDbCommand(commandText,con);
            //con.Open();
            //cmd.ExecuteNonQuery();
            ////}
            ////catch(Exception ex)
            ////{
            ////    log.Debug(ex);
            ////}
            ////finally{
            ////con.Close();
            ////    con.Dispose();
            ////}

            //con.Close();
            //  con.Dispose();
            DbProcessor.ExecuteNonQuery(commandType, commandText);
        }
        public object ExecuteScalar(string commandText)
        {
           // OleDbConnection con = GetConnection();
            
           // OleDbCommand cmd = new OleDbCommand(commandText, con);
           // con.Open();
           //object obj= cmd.ExecuteScalar();
           //con.Close();
           //return obj;
           return  DbProcessor.ExecuteScalar(CommandType.Text, commandText);
        }
        
    }
}
